package com.article.controller;

import com.article.entity.dto.SearchMemberDao;
import com.article.entity.pojo.Member;
import com.article.entity.vo.MemberVo;
import com.article.result.Result;
import com.article.service.MemberService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/member")
public class MemberController {
    private static final Logger log = LoggerFactory.getLogger(MemberController.class);
    @Autowired
    private MemberService memberService;

    @PostMapping("/search")
    public Result search(@RequestBody SearchMemberDao searchMemberDao) {
        log.info("搜索的searchMemberDao为:{}", searchMemberDao);
        MemberVo vo = memberService.search(searchMemberDao);
        return Result.success(vo);
    }

    @PostMapping("/add")
    public Result add(@RequestBody Member member) {
        log.info("添加的member为:{}", member);
        memberService.add(member);
        return Result.success();
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable("id") Long id) {
        log.info("删除的id为:{}", id);
        memberService.delete(id);
        return Result.success();
    }

    @DeleteMapping("/deletes")
    public Result deletes(@RequestBody Long[] ids) {
        log.info("删除的ids为:{}", ids);
        memberService.deletes(ids);
        return Result.success();

    }
}
